package com.example.demo.filter;


import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author: njz
 * @Description:
 * @Date: create in 2022/3/10 8:40
 */
@Order(-99999)
//@Component
public class TokenFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HeaderMapRequestWrapper requestWrapper = new HeaderMapRequestWrapper(req);
        String token = "eudcjbsjdbchjsbkjc.asvchdgvcjhdjc.ascuhudsi-sdhcjs";
        requestWrapper.addHeader("Authorization","Bearer "+token);
        chain.doFilter(requestWrapper, response);
    }

    @Override
    public void destroy() {

    }
}
